package selef.xiafan.dao;

import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import selef.xiafan.entity.system.SysRole;

import java.util.List;

public interface SysRoleDao extends JpaRepository<SysRole,Integer> {
    List<SysRole> findAllByName(String username);

    SysRole findById(int id);

    @Query(nativeQuery = true,value = "SELECT COUNT(*) FROM t_sys_role")
    Long countAll();

    @Query(nativeQuery = true,value = "SELECT * FROM t_sys_role LIMIT :page,:size")
    List<SysRole> findAllNoQuery(@Param("page")Integer page,@Param("size")Integer size);

    @Query(nativeQuery = true,value = "SELECT * FROM t_sys_role WHERE name_zh LIKE CONCAT('%',:nameZh,'%') LIMIT :page,:size" )
    List<SysRole> findAllByQuery(@Param("page") Integer page,  @Param("size") Integer size, @Param("nameZh") String nameZh);

    @Query(nativeQuery = true,value = "SELECT COUNT(*) FROM t_sys_role WHERE name_zh LIKE CONCAT('%',:nameZh,'%')")
    Long countAllByQuery(@Param("nameZh") String nameZh);
}
